import { myEnv } from '@/myEnv';
import { mergeRequest } from '@/utils';
import { MyOrderList_Web, MyOrderList_Res } from '@/pages/_server/_class/MyOrder/MyOrderList';

type SearchForm = {
    status: 'all' | 'unpaid' | 'paid' | 'cancelled';
    pageIndex: string;
};
/** 获得艺术品列表 */
export const apiGetApiOrderList = async (searchFrom:SearchForm) => {
    const response1: MyResponse<MyOrderList_Res[]> = await sendRequest(searchFrom);
    if (!response1) return;
    const webData = response1.data.map((item) => {
        return new MyOrderList_Web().immit_response(item);
    });
    const resonlse2: MyResponse<MyOrderList_Web[]> = { ...response1, data: webData };
    return resonlse2;
};

const sendRequest = async (searchFrom:SearchForm) => {
    let response1: MyResponse<MyOrderList_Res[]>;
    if (myEnv.IS_ON_LINE) {
        response1 = await mergeRequest({
            url: 'order',
            method: 'GET',
            data:{...searchFrom}
        });
    } else {
        response1 = {
            code: '200',
            message: 'ok',
            data: [
                {
                    goodsId: '1',
                    createTime: '2022-09-15T00:19:15.000Z',
                    price: '30.05',
                    paymentMethod: 'wechat',
                    status: 'unpaid',
                },
                {
                    goodsId: '2',
                    createTime: '2022-09-15T00:20:27.000Z',
                    price: '30.05',
                    paymentMethod: 'wechat',
                    status: 'unpaid',
                },
                {
                    goodsId: '3',
                    createTime: '2022-09-15T00:20:29.000Z',
                    price: '30.05',
                    paymentMethod: 'wechat',
                    status: 'unpaid',
                },
                {
                    goodsId: '5',
                    createTime: '2022-09-15T00:20:36.000Z',
                    price: '30.05',
                    paymentMethod: 'wechat',
                    status: 'unpaid',
                },
                {
                    goodsId: '5',
                    createTime: '2022-09-15T00:24:53.000Z',
                    price: '30.05',
                    paymentMethod: 'wechat',
                    status: 'unpaid',
                },
                {
                    goodsId: '5',
                    createTime: '2022-09-15T01:12:22.000Z',
                    price: '30.05',
                    paymentMethod: 'wechat',
                    status: 'unpaid',
                },
                {
                    goodsId: '5',
                    createTime: '2022-09-15T01:15:04.000Z',
                    price: '30.05',
                    paymentMethod: 'wechat',
                    status: 'unpaid',
                },
                {
                    goodsId: '5',
                    createTime: '2022-09-15T01:17:36.000Z',
                    price: '30.05',
                    paymentMethod: 'wechat',
                    status: 'unpaid',
                },
                {
                    goodsId: '1',
                    createTime: '2022-09-15T01:40:35.000Z',
                    price: '30.05',
                    paymentMethod: 'wechat',
                    status: 'unpaid',
                },
            ],
        };
    }
    return response1;
};
